package com.demo.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.demo.domain.Config;
import com.demo.model.R;
import com.demo.service.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/configs")
@RestController
public class ConfigController {

    @Autowired
    private ConfigService configService;

    @GetMapping
    public R<Page<Config>> findByPage(Page<Config> page,String type ,String code,String name){
        Page<Config> configPage = configService.findByPage(page, type, code, name);
        return R.ok(configPage);
    }


    @PostMapping
    public R add(@RequestBody @Validated Config config){
        boolean save = configService.save(config);
        if(save){
           return R.ok("新增成功");
        }
        return R.fail("新增失败");
    }

    @PatchMapping
    public R update(@RequestBody @Validated Config config){
        boolean update = configService.updateById(config);
        if(update){
            return R.ok("新增成功");
        }
        return R.fail("新增失败");
    }
}
